

import os

import mmcv
# using a pre-trained detector. 预训练配置
from mmcv import Config

from mmdet.datasets import build_dataset
from mmdet.models import build_detector
from mmdet.apis import train_detector, inference_detector, show_result_pyplot

from mmdet.apis import init_detector, inference_detector, show_result_pyplot

root_path=r"/home/deepin/Documents/openmmlab/mmdetection/"

config_file = root_path+'mytest/coco128/work_dir/cocoDataset_cfgformat.py'

checkpoint_file = root_path+'mytest/coco128/work_dir/latest.pth'

device = 'cuda:0'

# 初始化检测器--构建模型
model = init_detector(config_file, checkpoint_file, device=device)

# 查看 faster RCNN模型结构：
for name,module in model.named_children():
    print(name)
    [ print(F'    {n}') for n,_ in module.named_children() ]



# 推理 显示
img = mmcv.imread(root_path+'data/coco/train2017/3.jpg')

result = inference_detector(model, img) # -------如何 把 训练完成的，进行推理，这个不知道  如何加载呢
print(result)
show_result_pyplot(model, img, result,score_thr=0.4,out_file=root_path+'data/result.jpg') #显示 并保存结果



